package com.gx.service.impl;

import com.gx.domain.SysMenu;
import com.gx.domain.SysRoleMenu;
import com.gx.domain.SysRoleMenuExample;
import com.gx.id.DefaultIdGenerator;
import com.gx.id.IdGenerator;
import com.gx.mapper.SysRoleMenuMapper;
import com.gx.service.api.SysRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SysRoleMenuServiceImpl implements SysRoleMenuService {

    private IdGenerator idGenerator = DefaultIdGenerator.getInstance();

    @Autowired
    private SysRoleMenuMapper sysRoleMenuMapper;

    @Override
    public int save(SysRoleMenu sysRoleMenu) {
        sysRoleMenu.setId(idGenerator.generateId());
        sysRoleMenu.setCreateDate(new Date());
        return sysRoleMenuMapper.insert(sysRoleMenu);
    }

    @Override
    public List<SysRoleMenu> queryMenuSysRoleMenu(Long roleId) {
        SysRoleMenuExample sysRoleMenuExample = new SysRoleMenuExample();
        SysRoleMenuExample.Criteria criteria = sysRoleMenuExample.createCriteria();
        criteria.andRoleIdEqualTo(roleId);
        return sysRoleMenuMapper.selectByExample(sysRoleMenuExample);
    }
}
